//
//  HomeViewController.swift
//  ShouChong
//
//  Created by 陈友文 on 2024/6/11.
//

import UIKit
import SwiftUI
import MMDrawerController
//import WatchConnectivity

class HomeViewController: BaseViewController {
//    let session = WCSession.default
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
//        if WCSession.isSupported() {
//            session.delegate = self
//            session.activate()
//        }
    }
    
    private func setupUI() {
        self.title = "首页"
        
//        let colorName = GetMainColorTool.getMainColor()
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "text.alignleft")?.withTintColor(UIColor(named: "color_text_black")!, renderingMode: .alwaysOriginal), style: .plain, target: self, action: #selector(pushSettingVC))
        let homeView = HomeView {
            let dateVC = DateDetailViewController()
            self.navigationController?.pushViewController(dateVC, animated: true)
        } playClickBlock: {
            let playVC = PlayViewController()
            self.navigationController?.pushViewController(playVC, animated: true)
        }
        let hostVC = UIHostingController(rootView: homeView)
        hostVC.view.backgroundColor = UIColor(named: "color_bg")
        hostVC.view.frame = kScreenBounds
        self.view.addSubview(hostVC.view)
    }
    
    @objc private func pushSettingVC() {
        if self.mm_drawerController.openSide == .left {
            self.mm_drawerController.closeDrawer(animated: true) { flag in
                
            }
        } else {
            self.mm_drawerController.open(.left, animated: true) { flag in
                
            }
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.mm_drawerController.closeDrawerGestureModeMask = .all
        self.mm_drawerController.openDrawerGestureModeMask = .all
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.mm_drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureMode(rawValue: 0)
        self.mm_drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureMode(rawValue: 0)
       
    }
    


}

//extension HomeViewController:WCSessionDelegate {
//    func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: (any Error)?) {
//        DPrint("\(session)")
//    }
//    
//    func sessionDidBecomeInactive(_ session: WCSession) {
//        DPrint("\(session)")
//    }
//    
//    func sessionDidDeactivate(_ session: WCSession) {
//        DPrint("\(session)")
//    }
//    
//    func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
//        DPrint(message)
//    }
//    
//    
//}
